package com.cn.组件扫描;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * @Auther: 代理仁
 * @Date: 2019/7/7 18:00
 * @Description:自定义扫描规则
 */
public class MyFilterType implements TypeFilter {
     /*
      * @Author 代理仁
      * @Description 自定义规则 只要包含o的全扫描
      * @Date 2019/7/7 18:01
      * @Param
      * @return
      */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        //获取当前类注解的信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        //获取当前正在扫描的类的类信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        //获取当前类资源（类的路径）
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();
        System.out.println("路径:"+resource.getFilename()+",类名"+className);
        if(className.contains("o")){
            return true;
        }
        return false;
    }
}
